package cn.cmvideo.springboot.system.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import cn.cmvideo.springboot.business.model.Message;
import lombok.extern.slf4j.Slf4j;

@ControllerAdvice
@Slf4j
public class ApiExceptionHandler
{
	@ExceptionHandler(AuthorizationException.class)
	@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
	@ResponseBody
	public ResponseEntity<Message> handleAuthorizationExceptionExceptionError(RuntimeException ex)
	{
		ex.printStackTrace();
		log.error(">>>>>>", ex);
		Message message = new Message();
		message.setCode(String.valueOf(HttpStatus.UNAUTHORIZED.value()));
		message.setMessage(ex.getMessage());
		return new ResponseEntity<Message>(message, HttpStatus.UNAUTHORIZED);
	}

}
